import 'babel-polyfill'
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUi from 'element-ui'
import 'lib-flexible/flexible.js'
import { postRequest, getRequest, deleteRequest } from '@/libs/axios.js'
import 'element-ui/lib/theme-chalk/index.css'
import { message } from '@/libs/resetMessage.js'
import i18n from './lang'

window.isReresh = false

Vue.config.productionTip = false
// 使用ElementUi组件
Vue.use(ElementUi)
Vue.prototype.$message = message
// http请求二次封装
Vue.prototype.postRequest = postRequest
Vue.prototype.getRequest = getRequest
Vue.prototype.deleteRequest = deleteRequest

Vue.use(ElementUi, {
  i18n: (key, value) => i18n.t(key, value)
})

Vue.directive('preventReClick', {
  inserted (el) {
    el.addEventListener('click', () => {
      if (!el.disabled) {
        el.disabled = true
        setTimeout(() => {
          el.disabled = false
        }, 1500)
      }
    })
  }
})

Vue.filter('dataFormat', function (originVal) {
  const date = new Date(originVal)

  const y = date.getFullYear()
  // padStart(没有几位数字, '在字符串前面填补什么')
  const m = (date.getMonth() + 1 + '').padStart(2, '0')
  const d = (date.getDate() + '').padStart(2, '0')
  // const hh = (date.getHours() + '').padStart(2, '0')
  // const mm = (date.getMinutes() + '').padStart(2, '0')
  // const ss = (date.getSeconds() + '').padStart(2, '0')
  // 过滤器必须return数据
  return `${y}-${m}-${d}`
})

window.vm = new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')
